package com.dmxh.controller;

import com.dmxh.params.QueryParams;
import com.dmxh.pojo.TbBrand;
import com.dmxh.result.Result;
import com.dmxh.service.BrandService;
import com.dmxh.vo.BrandVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @PostMapping("/queryPage")
    public Result queryPage(@RequestBody QueryParams<BrandVo> queryParams) {
        return new Result("1","操作成功",brandService.queryPage(queryParams));
    }

    @GetMapping("/queryBrandByName/{name}")
    public Result queryBrandByName(@PathVariable String name) {
        return new Result("1", "操作成功", brandService.queryBrandByName(name));
    }

    @PostMapping("/save")
    public Result save(@RequestBody TbBrand tbBrand) {
        if (tbBrand.getId() == null) {
            brandService.addInfo(tbBrand);
            return new Result("1", "操作成功");
        }
        brandService.updateInfo(tbBrand);
        return new Result("1", "操作成功");
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteByName(@PathVariable Integer id) {
        brandService.deleteById(id);
        return new Result("1", "操作成功");
    }

    @PatchMapping("/deleteBatch")
    public Result deleteBatch(@RequestBody Integer[] ids) {
        brandService.deleteBatch(ids);
        return new Result("1", "操作成功");
    }

    @GetMapping("/queryAllBrand")
    public Result queryAllBrand() {
        return new Result("1", "操作成功", brandService.queryAllBrand());
    }


}
